﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ChurchData.EBulletin
{
    public partial class EBulletinSend : ChurchForm
    {
        public EBulletinSend()
        {
            InitializeComponent();

            lblSubscriberCount.Text = BuckleyChurch.Business.ElectronicBulletin.EBulletin.GetSubscriberCount().ToString();
            grdBulletins.DataSource = BuckleyChurch.Business.ElectronicBulletin.EBulletin.GetBulletinRecords();
            grdBulletins.Columns["BulletinPK"].Visible = false;
        }

        private void btnSend_Click(object sender, EventArgs e)
        {
            if (grdBulletins.SelectedRows.Count == 0)
            {
                MessageBox.Show("Please select which bulletin to send.");
                return;
            }

            int bulletinPK = (int)grdBulletins.SelectedRows[0].Cells["BulletinPK"].Value;
            DateTime bulletinDate = (DateTime)grdBulletins.SelectedRows[0].Cells["BulletinDate"].Value;
            string fileName = grdBulletins.SelectedRows[0].Cells["FileName"].Value.ToString();

            Cursor.Current = Cursors.WaitCursor;
            int sendCount = BuckleyChurch.Business.ElectronicBulletin.EBulletin.SendBulkEmail(bulletinPK, bulletinDate, fileName);
            Cursor.Current = Cursors.Default;

            StringBuilder sb = new StringBuilder();
            sb.AppendLine("Send Completed");
            sb.Append(sendCount + " sent");
            MessageBox.Show(sb.ToString());
        }
    }
}